/* @(#)GSOrderDetailSubmitToBM.java    
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li     2006-2-20    新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import system.LoginContext;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSBusOrderProcesser;
import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.business.GSOrderProcessor;
import com.hitrust.gs.business.GSUniteGwProcessor;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.form.GSOrderDetailSubmitQueryForm;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.GSOrderAuthorizeSaveVO;

/**
 * 向采购网提交订单明细
 */
public class GSOrderDetailSubmitToApepAction extends GSBaseAction {


    public String execute(GSBaseForm aForm) throws Exception {
        GSOrderDetailSubmitQueryForm tForm = (GSOrderDetailSubmitQueryForm)aForm;
        String[] tOrderDetailIds = tForm.getOrderDetailIds();
        //取得当前操作员可查询的订货单位和送货地址
        LoginContext tOperBean = (LoginContext)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        GSUniteGwProcessor processer = new GSUniteGwProcessor();
        ArrayList ary = processer.getWareHouseLevelName(tOperBean.getLoginWarehouseCode(),tOperBean.getLoginWarehouseCode());
        aForm.getRequest().setAttribute("organdaddr",ary);
        //取得产品分类
        GSManufactureProcessor tManufProc = new GSManufactureProcessor();
        tManufProc.getManufactureOfLevel(aForm);
        String msg = "";
        try{
            if(tOrderDetailIds != null && tOrderDetailIds.length > 0){
                ArrayList newList=new ArrayList();
                for (int i = 0; i < tOrderDetailIds.length; i++) {
                    GSOrderAuthorizeSaveVO vo=new GSOrderAuthorizeSaveVO();
                    vo.detailId=tOrderDetailIds[i];
                    newList.add(vo);
                }
                GSBusOrderProcesser tBOProc = new GSBusOrderProcesser();
                msg= tBOProc.orderSubmitNewToApep(tOperBean, newList,null);
                tForm.getRequest().setAttribute("message",msg);
                tForm.getRequest().setAttribute("requery","true");
                return GSBaseConstants.FORWARD_SUCCESS;
                
            }else{
                GSLogWriter.error(this,"传入的参数－订单明细ID为空");
                throw new GSException(GSException.E00003,GSException.E00003_MSG);   
            }
        }catch(GSException e){
            tForm.getRequest().setAttribute("action","A150301.do");
            throw e;
        }catch(Exception e){
            tForm.getRequest().setAttribute("action","A150301.do");
            throw e;
        }
        
    }

}
